package com.example.backend.api.controller;


import com.example.backend.api.common.Result;
import com.example.backend.api.service.impl.ProjectServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.text.ParseException;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xwyzsn
 * @since 2023-03-07
 */
@RestController
@RequestMapping("/api/project")
@CrossOrigin(origins = "*",maxAge = 3600)
public class ProjectController {


    @Autowired
    private ProjectServiceImpl projectServiceimpl;
    @PostMapping("/getall")
    public Result getAll(@RequestParam(value = "project_id",required = false) Integer deptId,
                         @RequestParam(value = "name",required = false) String projectName
                         ){
        return projectServiceimpl.getAll(deptId,projectName);
    }

    @GetMapping("delete")
    public Result delete(@RequestParam("project_id") String id){
        return projectServiceimpl.delete(Integer.parseInt(id));
    }
    @GetMapping("notfinish")
    public Result getNotFinish(){
        return projectServiceimpl.getNotFinish();
    }
    @PostMapping("update")
    public Result update(@RequestParam("project_id") String id,
                         @RequestParam(value = "name",required = false) String name,
                         @RequestParam(value = "code",required = false) String code,
                         @RequestParam(value = "createdTime",required = false) String  startTime,
                         @RequestParam(value = "endTime",required = false) String  endTime,
                         @RequestParam(value = "status",required = false) String status) throws ParseException {
        return projectServiceimpl.updateProject(id,name,code,startTime,endTime,status);
    }

    @PostMapping("add")
    public Result add(@RequestParam(value = "name",required = false) String name,
                      @RequestParam(value = "code",required = false) String code,
                      @RequestParam(value = "createdTime",required = false) String  startTime,
                      @RequestParam(value = "endTime",required = false) String  endTime,
                      @RequestParam(value = "status",required = false) String status,
                      @RequestParam(value = "projectNum" ) Integer projectNum) throws ParseException {
        return projectServiceimpl.addProject(name,code,startTime,endTime,status,projectNum);
    }
}
